package com.doudizu.shoesonline.controller;

import com.doudizu.shoesonline.common.BaseResponse;
import com.doudizu.shoesonline.common.ResultUtils;
import com.doudizu.shoesonline.model.dto.brand.BrandDTO;
import com.doudizu.shoesonline.model.dto.brand.BrandQuery;
import com.doudizu.shoesonline.model.entity.Brand;
import com.doudizu.shoesonline.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ln
 */
@RestController
@RequestMapping("/brand")
@Api(tags = "品牌模块")
public class BrandController {
    @Resource
    private BrandService brandService;

    @GetMapping("/list")
    @ApiOperation("查询所有品牌")
    public BaseResponse getBrands(BrandQuery brandQuery) {
        return ResultUtils.success(brandService.getBrands(brandQuery));
    }


    @GetMapping("/brandName")
    @ApiOperation("查询品牌")
    public BaseResponse searchBrands(String brandName) {
        return ResultUtils.success(brandService.searchBrands(brandName));
    }

    @GetMapping
    @ApiOperation("获取单个品牌信息")
    public BaseResponse getBrand(String brandId) {
        return ResultUtils.success(brandService.getBrand(brandId));

    }


    @PostMapping("/add")
    @ApiOperation("添加品牌")
    public BaseResponse addBrand(@RequestBody BrandDTO brandDTO) {
        brandService.addBrand(brandDTO.getBrandName(),brandDTO.getPicIds());
        return ResultUtils.success(null);
    }

    @PostMapping("/status")
    @ApiOperation("修改品牌状态")
    public BaseResponse lockOrUnlock(@RequestBody Brand brand) {
        brandService.updateById(brand);
        return ResultUtils.success(null);
    }

    @PostMapping("/update")
    @ApiOperation("修改品牌")
    public BaseResponse update(@RequestBody BrandDTO brandDTO) {
        brandService.updateBrand(brandDTO);
        return ResultUtils.success(null);
    }

    @PostMapping("/delete")
    @ApiOperation("删除品牌")
    public BaseResponse delete(@RequestParam List<Integer> ids) {
        brandService.removeBatchByIds(ids);
        return ResultUtils.success(null);
    }
}
